package com.sense.kukoo.biz_me.vm

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.sense.kukoo.common.event.LogoutEvent
import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.mvvm.vm.BaseViewModel
import com.sense.kukoo.common.repo.Repo
import com.sense.kukoo.common.repo.bean.ResultBean
import com.sense.kukoo.lib_logger.LoggerManager
import org.greenrobot.eventbus.EventBus

class ManageAccountViewModel : BaseViewModel() {

    private val TAG: String = javaClass.simpleName

    val action_toShowDialog: MutableLiveData<Boolean> = MutableLiveData()

    override fun createModel(): BaseMvvmModel? = null

    override fun initData() {}

    fun onBtnDeleteAccount(){
        action_toShowDialog.postValue(true)
    }

    fun onDeleteAccount(){
        //
        toView(ACTION_SHOW_DIALOG)
        request {
            val result = Repo.http.removeUser()
            if(result.code == ResultBean.CODE_SUCCESS && result.success){
                LoggerManager.e("removeUser() success")
                EventBus.getDefault().post(LogoutEvent())
            } else {
                Log.e(TAG, "result=" + result.msg)
                result.msg.let { sendHintMessage(it) }
            }
            toView(ACTION_HIDE_DIALOG)
        }
    }

}